package com.zhiqingchun.web.user;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.zhiqingchun.dao.article.ArticleResult;
import com.zhiqingchun.dao.article.IArticleDao;
import com.zhiqingchun.dao.category.ICategoryDao;
import com.zhiqingchun.pojo.ArticleDO;

@Controller
@RequestMapping("/deleteArticle.html")
public class DeleteArticleController {

	@RequestMapping(method = RequestMethod.GET)
	public String get(ModelMap map, HttpServletRequest request, HttpServletResponse response,
			int id) {
		 ArticleDO articleDO = articleDao.byId(id);
		 ArticleResult articleResult = articleDao.delete(articleDO);
		 if (articleResult.isSuccess()) {
			 return "redirect:user.html?id=" + articleDO.getAuthor();
		 }
		 // XXX 此处应该返回报错页面
		 return null;
	}
	
	@Autowired
	private IArticleDao articleDao;
	
	@Autowired
	private ICategoryDao categoryDao;

	public ICategoryDao getCategoryDao() {
		return categoryDao;
	}

	public void setCategoryDao(ICategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}

	public IArticleDao getArticleDao() {
		return articleDao;
	}

	public void setArticleDao(IArticleDao articleDao) {
		this.articleDao = articleDao;
	}
	
}
